﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ShopUserCheck : Admin, IRequiresSessionState
{
    private Pagination _p;
    protected string wherestr = "";
    protected string linkhead = "";
    protected bool tag = false;
    protected Pagination m_pheader
    {
        get
        {
            Pagination p;
            if (this._p == null)
            {
                this._p = new Pagination();
                this._p.SQL_LeftJoinTable = "HL_User";
                this._p.SQL_LeftJoinField = "UserName";
                this._p.SQL_JoinField = "UserID";
                this._p.SQL_Fields = "UserInfoID,UserID,AuthenticationType,CompanyIdentify,MobileIdentify,BandShopIdentify,OtherIdentify1,OtherIdentify2,OtherIdentify3,OtherIdentify4";
                this._p.SQL_JoinField2 = "UserID";
                this._p.P_Object = "位会员";
                p = this._p;
            }
            else
            {
                p = this._p;
            }
            return p;
        }
    }
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(5))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Identify");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.GridView1DataSoucreBind();
        }
    }
    protected string GetType(string str)
    {
        string result;
        if (str != null)
        {
            if (str == "1")
            {
                result = "通过认证";
                return result;
            }
            if (str == "9")
            {
                result = "等待认证";
                return result;
            }
            if (str == "0")
            {
                result = "取消认证";
                return result;
            }
            if (str == "-1")
            {
                result = "拒绝认证";
                return result;
            }
        }
        result = "未申请";
        return result;
    }
    protected void IdentifyUserType(object sender, CommandEventArgs e)
    {
        string text = Text.CheckNumList(base.Request["chk_select"]);
        string text2 = "";
        int num = Convert.ToInt32(e.CommandName);
        string text3 = "";
        for (int i = 0; i < this.IdentifyCheckBoxList.Items.Count; i++)
        {
            if (this.IdentifyCheckBoxList.Items[i].Selected)
            {
                object obj = text3;
                text3 = string.Concat(new object[]
				{
					obj,
					this.IdentifyCheckBoxList.Items[i].Value,
					"=",
					num,
					","
				});
                if (this.IdentifyCheckBoxList.Items[i].Value == "AuthenticationType")
                {
                    text2 = "1";
                }
                else
                {
                    if (this.IdentifyCheckBoxList.Items[i].Value == "CompanyIdentify")
                    {
                        text2 += ",2";
                    }
                    else
                    {
                        if (this.IdentifyCheckBoxList.Items[i].Value == "BandShopIdentify")
                        {
                            text2 += ",3";
                        }
                    }
                }
            }
        }
        if (text3 != string.Empty && text != string.Empty)
        {
            text3 += ",";
            text3 = text3.Replace(",,", "");
            string sql = string.Concat(new string[]
			{
				"Update hl_userinfo Set ",
				text3,
				" Where userid in(",
				text,
				")"
			});
            this.conn.Execute(sql);
            if (text2 == ",2")
            {
                text2 = "2";
            }
            if (text2 == ",3")
            {
                text2 = "3";
            }
            if (text2 == ",2,3")
            {
                text2 = "2,3";
            }
            string sql2 = string.Concat(new object[]
			{
				"Update HLShop_Application Set Status=",
				num,
				" ,Editor='",
				base.admin.AdminName,
				"' ,UpdateTime='",
				DateTime.Now,
				"'  Where IdentifyType in(",
				text2,
				") AND UserID in(",
				text,
				")"
			});
            this.conn.Execute(sql2);
            this.GridView1DataSoucreBind();
        }
    }
    protected void QuickSearchBtn_Click(object sender, EventArgs e)
    {
        this.tag = false;
        this.GridView1DataSoucreBind();
    }
    protected void GridView1DataSoucreBind()
    {
        this.GetQuestString();
        int num = Fetch.GetID("page");
        if (num == 0)
        {
            num = 1;
        }
        int pageSize = this.GridView1.PageSize;
        DataTable dataTable = this.m_pheader.GetDataTable("HL_UserInfo", num, pageSize, "UserInfoID", this.wherestr, "UserInfoID Desc", this.conn, null);
        this.GridView1.DataSource = dataTable;
        this.GridView1.DataBind();
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            HiddenField hfAuthenticationType = (HiddenField)gridViewRow.FindControl("hfAuthenticationType");
            Literal ltrAuthenticationType = (Literal)gridViewRow.FindControl("ltrAuthenticationType");
            HyperLink hlAuthenticationType = (HyperLink)gridViewRow.FindControl("AuthenticationType");
            this.IdentifyStatue(hfAuthenticationType, ltrAuthenticationType, hlAuthenticationType);
            HiddenField hfAuthenticationType2 = (HiddenField)gridViewRow.FindControl("hfCompanyIdentify");
            Literal ltrAuthenticationType2 = (Literal)gridViewRow.FindControl("ltrCompanyIdentify");
            HyperLink hlAuthenticationType2 = (HyperLink)gridViewRow.FindControl("CompanyIdentify");
            this.IdentifyStatue(hfAuthenticationType2, ltrAuthenticationType2, hlAuthenticationType2);
        }
        this.m_pheader.P_LinkHead = this.linkhead;
        this.PagePanel.Text = this.m_pheader.ShowPagePanel();
    }
    private void IdentifyStatue(HiddenField hfAuthenticationType, Literal ltrAuthenticationType, HyperLink hlAuthenticationType)
    {
        if (hfAuthenticationType != null)
        {
            string value = hfAuthenticationType.Value;
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Trim() != "1" && value.Trim() != "9" && value.Trim() != "0" && value.Trim() != "-1")
                {
                    if (hlAuthenticationType != null && ltrAuthenticationType != null)
                    {
                        ltrAuthenticationType.Text = hlAuthenticationType.Text;
                        ltrAuthenticationType.Visible = true;
                        hlAuthenticationType.Visible = false;
                    }
                }
                else
                {
                    if (hlAuthenticationType != null && ltrAuthenticationType != null)
                    {
                        ltrAuthenticationType.Visible = false;
                        hlAuthenticationType.Visible = true;
                    }
                }
            }
            else
            {
                if (hlAuthenticationType != null && ltrAuthenticationType != null)
                {
                    ltrAuthenticationType.Text = hlAuthenticationType.Text;
                    ltrAuthenticationType.Visible = true;
                    hlAuthenticationType.Visible = false;
                }
            }
        }
    }
    protected void GetQuestString()
    {
        string selectedValue = this.DropIdentity.SelectedValue;
        if (Fetch.Get("un") != string.Empty && this.tag)
        {
            this.TxtNickName.Text = Fetch.Get("un");
        }
        if (!string.IsNullOrEmpty(this.TxtNickName.Text))
        {
            string text = Text.ReplaceBadChar(this.TxtNickName.Text);
            this.wherestr = this.wherestr + "and HL_UserInfo.UserID in(Select UserID From [HL_User] Where UserName like '%" + text + "%') ";
            this.linkhead = this.linkhead + "&un=" + base.Server.UrlEncode(text);
        }
        string text2 = "";
        for (int i = 0; i < this.ChkAuthenticationType.Items.Count; i++)
        {
            if (this.ChkAuthenticationType.Items[i].Selected)
            {
                string text3 = text2;
                text2 = string.Concat(new string[]
				{
					text3,
					"or HL_UserInfo.",
					this.ChkAuthenticationType.Items[i].Value,
					"=",
					selectedValue,
					" "
				});
            }
        }
        if (text2 != string.Empty)
        {
            text2 = "or" + text2;
            text2 = text2.Replace("oror", "and (") + ")";
        }
        this.wherestr += text2;
        if (this.wherestr != "")
        {
            this.wherestr = "and" + this.wherestr;
            this.wherestr = this.wherestr.Replace("andand", "where");
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.GridView1DataSoucreBind();
    }
}
